In Svelte, stores are reactive objects that hold values and notify subscribers when the value changes. Inside a component, you can subscribe to a store in two main ways: using the $store auto-subscription syntax or manually subscribing.
The simplest way to use a store in a Svelte component is to prefix it with $. This automatically subscribes to the store and updates the component reactively whenever the value changes.
You can also manually subscribe to a store using its subscribe method. This is useful when you need to perform additional logic whenever the store changes.
Use $store syntax for simple reactive updates—it auto-subscribes and cleans up automatically.
Manually subscribe only if you need custom behavior or side effects on value changes.
Always unsubscribe in onDestroy when manually subscribing to prevent memory leaks.
Stores can be shared globally or scoped to a component depending on the use case.